﻿#pragma once
#include <core/Swnd.h>

namespace SOUI
{
	class  SSwitch : public SWindow, public ITimelineHandler
	{
		SOUI_CLASS_NAME(SSwitch, L"switch")
	public:
		SSwitch();
		~SSwitch();
	protected://SWindow的虚函数
		virtual CSize GetDesiredSize(LPCRECT pRcContainer);
		virtual void OnStateChanged(DWORD dwOldState, DWORD dwNewState);
		// 通过 ITimelineHandler 继承
		virtual void OnNextFrame();

	public://属性处理
		BOOL IsOpen();
		void SetOpen(BOOL bOpen);
	protected:
		void OnPaint(IRenderTarget *pRT);
		void OnLButtonUp(UINT nFlags, CPoint point);
		void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
		HRESULT OnAttrOpen(const SStringW& strValue, BOOL bLoading);

		UINT _GetDrawState();

		//SOUI控件消息映射表
		SOUI_MSG_MAP_BEGIN()
			MSG_WM_PAINT_EX(OnPaint)
			MSG_WM_LBUTTONUP(OnLButtonUp)
			MSG_WM_KEYDOWN(OnKeyDown)
		SOUI_MSG_MAP_END()

		ISkinObj *m_pSkin;
		ISkinObj *m_pSkinForce;

		SOUI_ATTRS_BEGIN()
			ATTR_SKIN(L"skin", m_pSkin, TRUE)
			ATTR_SKIN(L"skinforce", m_pSkinForce, TRUE)
			ATTR_CUSTOM(L"open", OnAttrOpen)
		SOUI_ATTRS_END()
	private:
		BOOL m_BOpen;			//是否为打开状态
		BOOL m_BOpenTarget;     //目标状态
		BOOL m_BChangeing;      //正在改变状态..	
		int  m_FrameCount;		//动画帧数
		int  m_FrameNow;		//当前帧
	};

}